#include<stdlib.h>
#include<stdio.h>
typedef struct LST
{    	  	   	
    int num;
    struct LST *next;
}    	  	   	 LST;
LST *mycreat()                           //2
{    	  	   	
    int data = 0;
    LST *head = NULL, *p = NULL, *q = NULL;  //1
    head = (LST*)malloc(sizeof(LST));  //1
    q = head;
    printf("请输入链表数据(整型)并以空格空开,以-1为最后一个数,回车结尾:\n");
    scanf("%d", &data);
    while (data != -1)
    {    	  	   	
        p = (LST*)malloc(sizeof(LST));      //1
        q->next = p;                        //1
        p->num = data;                     //1
        q = p;                            //1
        scanf("%d", &data);               //1
    }
    q->next = NULL;                     //1
    return head;                     
}    	  	   	
  
void myprint(LST *head)         //2
{    	  	   	
     LST *p;
     p=head->next;              //1
    while (p != NULL)              //1
    {    	  	   	
        printf("%4d", p->num);         //1
        p = p->next;                 //1
    }
    
}    	  	   	
 
void clear(LST *head)                //2
{    	  	   	
    LST *p = NULL;              //1
    p = head;                    //1
    while (p->next != NULL)          //1
    {    	  	   	
        p = p->next;          //1
        p->num = 0;
    }
}    	  	   	
LST *A_B(LST *A, LST *B)//计算A-B，计算结果保存在A中//2
{    	  	   	
    LST *pa, *pa_prev, *pb;          
    int e, flag;
    pa = A->next;                      
    pa_prev = A;
    while (pa != NULL)          //2
    {    	  	   	
        flag = 0;
        e = pa->num;            
        pb = B->next;           
        while (pb != NULL)       //2 
        {    	  	   	
            if (pb->num == e)       
            {    	  	   	
                if (pa == A)
                {    	  	   	
                    A = pa->next;
                    pa_prev = pa->next;   
                    pa = pa->next;
                    flag = 1;
                }
                else if (pa->next == NULL)     //2
                {    	  	   	
                    pa = NULL;
                    pa_prev->next = pa;
                    flag = 1;
                }
                else//非表头元素和表尾元素       //2
                {    	  	   	
                    pa_prev->next = pa->next;
                    pa = pa->next;
                    flag = 1;
                }
                break;
            }
            else pb = pb->next;
        }
        if (flag == 0)
        {    	  	   	
            pa_prev = pa;
            pa = pa->next;
        }
    }
    return A;
}    	  	   	
int main()                      //2
{    	  	   	
    int k = 0, m = 0, l = 0;
    LST *head = NULL;
    LST *head1 = NULL;
    LST *p;
    head = mycreat();          //2
    head1 = mycreat();
    p = A_B(head, head1);         //2
    printf("输出A链表中删除后的结点信息:\n");
    myprint(p);             //2
    clear(head);
    clear(head1);
    clear(p); 
}